<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.util.List"%>
<%@ page import="org.dualr.litelog.entity.Category"%>
<%@ page import="org.dualr.litelog.entity.Post"%>
<%@ page import="org.dualr.litelog.dao.CategoryDao"%>
<%@ page import="org.dualr.litelog.dao.PostDao"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Post Edit - LiteLog Administration</title>
<script type="text/javascript" src="../js/ckeditor/ckeditor.js"></script>
<style type="text/css">
	body {
		font-size: 12px;
		margin-left:0px;
		margin-right:0px;
	}
	h1{
	background: #EBF4D8;
	line-height: 28px;
	padding: 4px 0 0 1em;
	border-bottom: 1px solid #87A34D;
	color: green;
	font-size: 14px;
}
	input[type='text'] {
		border: 1px solid #666666;
		color: #333333;
		width:300px;
	}
	textarea{
		font-size:12px;
	}
</style>
</head>
<body>
<h1>编辑文档</h1>
<%
	Long id = Long.parseLong(request.getParameter("id"));
	List<Category> categoryList = CategoryDao.getInstance().getListByProperty("type","post","string"); 
	Post post = PostDao.getInstance().getById(id);
%>
	<form action="../admin?entity=post&option=edit" method="post">
	<input type="hidden" value="<%=id%>" name="id"></input>
	<table width="100%" style="font-size:12px;">
		<tr>
			<td align="right" width="100">标题:</td>
			<td align="left" width="auto"><input type="text" name="title" value="<%=post.getTitle()%>" /></td>
		</tr>
		<tr>
			<td align="right">类别:</td>
			<td align="left">
				<select name="categoryId" >
				<%
					if (categoryList.size() != 0){
												for(Category category : categoryList){
													if(post.getCategoryId() == category.getId()){
				%>
										<option value="<%=category.getId()%>" selected="selected"><%=category.getName()%></option>
										<%
									}else{
										%>
										<option value="<%=category.getId()%>"><%=category.getName()%></option>
										<%
										}
									}
							}
				%>	
				</select>
			</td>
		</tr>
		<tr>
			<td align="right">配图:</td>
			<td align="left"><input type="text" name="image" value="<%=post.getImage()%>"></input></td>
		</tr>
		<tr>
			<td align="right">标签:</td>
			<td align="left"><input type="text" name="tag" value="<%=post.getTag()%>"></input></td>
		</tr>
		<tr>
			<td align="right">摘要:</td>
			<td>
				<textarea id="articleDescription" name="decription" rows="4" cols="100%"><%=post.getDescription().getValue()%></textarea>
			</td>
		</tr>
		<tr>
			<td align="right">正文:</td>
			<td>
				<textarea id="articleContent"  name="content" rows="40" cols="80" style="width:100%"><%=post.getContent().getValue()%></textarea>
			</td>
		</tr>
		<tr>
			<td align="right">相关属性:</td>
			<td align="left">
				日志状态:<select name="status">
				<%
					if(post.getStatus().equals("publish")){
						%>
							<option value="publish" selected="selected">发布</option>
							<option value="draft">草稿</option>
							<option value="private">私密</option>
						<%
					}else if(post.getStatus().equals("draft")){
					%>
						<option value="publish" selected="selected">发布</option>
						<option value="draft" selected="selected">草稿</option>
						<option value="private">私密</option>
					<%
					}else{
					%>
						<option value="publish" selected="selected">发布</option>
						<option value="draft">草稿</option>
						<option value="private" selected="selected">私密</option>
					<%
				}
				%>
			
				</select>
				评论限制:<select name="commentStatus">
					<%
						if(post.getCommentStatus().equals("open")){
							%>
							<option value="open" selected="selected">允许所有</option>
							<option value="registered_only">登陆用户</option>
							<option value="close">关闭评论</option>
							<%
						}else if(post.getCommentStatus().equals("close")){
							%>
							<option value="open" >允许所有</option>
							<option value="registered_only">登陆用户</option>
							<option value="close" selected="selected">关闭评论</option>
							<%
						}else{
							%>
							<option value="open" >允许所有</option>
							<option value="registered_only" selected="selected">登陆用户</option>
							<option value="close" >关闭评论</option>
							<%		
						}
					%>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input type="submit" value="保存"></input>&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="取消"></input></td>
		</tr>
		
	</table>
	</form>
<script type="text/javascript" src="../js/ckeditor.js"></script>
</body>
</html>